import request from '@/utils/request'

// 创建回答
export function createAnswer(data) {
  return request({
    url: '/answer/create',
    method: 'post',
    data
  })
}

// 更新回答
export function updateAnswer(data) {
  return request({
    url: '/answer/update',
    method: 'put',
    data
  })
}

// 删除回答
export function deleteAnswer(answerId) {
  return request({
    url: `/answer/${answerId}`,
    method: 'delete'
  })
}

// 获取回答详情
export function getAnswerDetail(answerId) {
  return request({
    url: `/answer/${answerId}`,
    method: 'get'
  })
}

// 分页查询回答列表
export function getAnswerList(data) {
  return request({
    url: '/answer/list',
    method: 'post',
    data
  })
}

// 点赞/取消点赞回答
export function toggleLikeAnswer(answerId) {
  return request({
    url: `/answer/${answerId}/like`,
    method: 'post'
  })
}

// 踩/取消踩回答
export function toggleDislikeAnswer(answerId) {
  return request({
    url: `/answer/${answerId}/dislike`,
    method: 'post'
  })
}

// 设置最佳答案
export function setBestAnswer(answerId) {
  return request({
    url: `/answer/${answerId}/best`,
    method: 'post'
  })
}
